package com.tofine.smarthome.common.gson;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.tofine.smarthome.model.Room;

import java.lang.reflect.Type;

/**
 * @author ddMax
 * @since 2016/6/1 15:00.
 * 说明：Gson custom serializer
 */
public class RoomTypeAdapter implements JsonSerializer<Room> {

    @Override
    public JsonElement serialize(Room room, Type typeOfSrc, JsonSerializationContext context) {
        final JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("_id", room._id);
        jsonObject.addProperty("name", room.name);

        return jsonObject;
    }
}
